package cn.lg.soar.cms.biz.modules.other.service.impl;

import cn.lg.soar.cms.biz.modules.other.entity.BlockItem;
import cn.lg.soar.cms.biz.modules.other.mapper.BlockItemMapper;
import cn.lg.soar.cms.biz.modules.other.model.BlockItemVo;
import cn.lg.soar.cms.biz.modules.other.service.BlockItemService;
import cn.lg.soar.database.base.service.impl.BaseServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 页面元素内容
 * @author luguoxiang
 * @since 2025-02-23
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Service
public class BlockItemServiceImpl extends BaseServiceImpl<BlockItemMapper, BlockItem> implements BlockItemService {

    @Override
    public List<BlockItemVo> voListByBlockId(Long blockId, Integer limit) {
        return list(
                Wrappers.<BlockItem>lambdaQuery()
                        .eq(BlockItem::getPositionId, blockId),
                limit
        ).stream()
                .map(BlockItemVo::new)
                .collect(Collectors.toList());
    }

    @Override
    public boolean removeByBlockIds(Collection<Long> blockIds) {
        return remove(
                Wrappers.<BlockItem>lambdaQuery()
                        .in(BlockItem::getPositionId, blockIds)
        );
    }

}
